package lex.dm.utils;

import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Resources
{
	static
	{
		c = Resources.class;
		iconCache = new ConcurrentHashMap<String, Icon>( 20 );
	}
	private static final String IconPath = "/lex/dm/resources/images/";
	//=========================================================
	public static final String CATALOG_ICON = "database.PNG";
	public static final String TABLE_ICON = "table.PNG";
	public static final String FIELD_ICON = "field_large.PNG"; 
	public static final String TYPE_ICON = "info.PNG";
	public static final String CLOSE_ICON = "close.PNG";
	
	private static final Class<Resources> c;
	private static final Map< String, Icon> iconCache;
	private Resources(){}
	
	public static Icon getIcon( String key )
	{
		Icon icon = null;
		if( false == iconCache.containsKey( key ) )
		{
			icon = new ImageIcon( getURL( IconPath + key ) );
			iconCache.put( key, icon );
		}
		else
		{
			icon = iconCache.get( key );
		}
		return icon;
	}
	
	public static URL getURL( String name )
	{
		return c.getResource( name );
	}
}
